/*
使用QT实现Tcp协议的服务器和客户端
实现当服务器关闭后，所有未断开连接的客户端也随之关闭。
*/

#include "widget.h"
#include "ui_widget.h"
#include <QMessageBox>
#include <QTcpSocket>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
    , m_ptcpserver(new QTcpServer)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::init_network(){
    if(!m_ptcpserver->listen(QHostAddress::Any, 8099)){
        QMessageBox::information(this, "listen", "listen port fail");
        exit(1);
    }

    connect(m_ptcpserver, &QTcpServer::newConnection, this, &Widget::new_connection);
    return;
}

void Widget::new_connection(){
    QTcpSocket *ptcpsocket = m_ptcpserver->nextPendingConnection();

    return;
}

